package com.recommendation.action;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.quartz.SchedulerException;

import com.recommendation.service.RecommendEngine;

@Results({
	@Result(name="success", type="httpheader"),
	@Result(name="error", type="httpheader", params={"headers.msg", "error"})
})
public class StartAction extends ActionBase{

	public String execute()
	{
		_log.info("starting...");
		long userId = getUserId();
		RecommendEngine engine = new RecommendEngine(userId);
		try {
			if (engine.isStarted())
			{
				engine.resume();
			}
			else
			{
				boolean s = engine.start(userId);
				if (s)
				{
					
				}
				else
				{
					return ERROR;
				}
			}
		} catch (SchedulerException e) {
			error(e);
			return ERROR;
		}
		_log.info("started...");
		return SUCCESS;
	}
}
